<?php
/**
 * Handles functions and processes for development mode
 *
 * @package Concerto
 * @subpackage Utilities
 * @author Jason Raede <jason@torchdm.com>
 */
namespace application\utilities;

class Dev {
	/**
	 * Array of timers and their current times
	 *
	 * @var array
	 */
	protected $timers = array();
	
	/**
	 * Begin a timer
	 *
	 * @param string $timerName
	 */
	public function startTimer($timerName = null) {
		$this->timers[$timerName] = self::microtimeFloat();
	}
	
	/**
	 * Check a timer and echo its value
	 *
	 * @param string $timerName
	 */
	public function checkTimer($timerName = null) {
		$time = self::microtimeFloat();
		$diff = $time - ($this->timers[$timerName]);
		echo '<pre>Timer '.$timerName.' is at '.$diff.' seconds.</pre>';
	}
	
	/**
	 * Get the difference between now and timer start
	 *
	 * @param string $timerNAme
	 * @return float 
	 */
	public function getTimer($timerName = null) {
		$time = self::microtimeFloat();
		$diff = $time - ($this->timers[$timerName]);
		return $diff;
	}
	
	/**
	 * Get the current time in microseconds
	 *
	 * @return float
	 */
	public static function microtimeFloat() {
	    list($usec, $sec) = explode(" ", microtime());
	    return ((float)$usec + (float)$sec);
	}
	
	/**
	 * Report a debug string to the console
	 *
	 * @param string $string The report
	 */
	public static function reportDebug($string) {
		//if(getOption('debug_mode') == TRUE)
		echo '<pre><b>Debug:</b> '.$string.'</pre>';
	}
}
?>